// Tags:
#include <algorithm>
#include <cstdio>

const int N = 5e3 + 5;
int n, k, t, a[N];

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("coin.in", "r", stdin);
  freopen("coin.out", "w", stdout);
#endif
#endif

  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; ++i) { scanf("%d", &a[i]); }
    std::sort(a + 1, a + n + 1);
    if (k >= n) {
      printf("%d\n", a[n]);
    } else {
      int i = 1;
      long long sum = 0;
      for (; i <= n - k; ++i) sum += a[i];
      printf("%lld\n", std::max((long long)a[n], sum));
    }
  }
  return 0;
}